﻿$(function(){
	//默认隐藏
	$(".showPersonalContent").hide();
	$(".showEnterpriseContent").hide();
	//当日可发送短信次数
	var i = 5;
	//发送倒计时
	var num = 60;
	
	//定时器
	function timer(){
		var timeData  = setInterval(function(){ 
			//倒计时
			if(num > 1){
				$(".validateCode").attr("disabled","disabled");
				num -= 1;
				$(".validateCode").text("还剩" + num + "秒");
			}else{
				//关闭倒计时
				$(".validateCode").attr('disabled',false);
				$(".validateCode").text("获取验证码");
				num = 60;
				clearInterval(timeData);
				return;
			}
		},1000);
	};
	
	//获取验证码
	$(".validateCode").on("click",function(){
		$(".modal-footer").empty();
		$(".modal-footer").html("<button type='button' class='btn btn-info' data-dismiss='modal'>确认</button>");
		if(i > 0){
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("提示");
			$(".modal-body").text("验证码发送成功!");
			timer();
			i -= 1;
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("今日可发送次数已达上限!");
			i = 0;
		}	
	});
	
	//返回登录页
	$(".backBt").on("click",function(){
		$("#myModalLabel").text("提示");
		$(".modal-body").text("是否关闭当前页面并返回？");
		$(".modal-footer").empty();
		$(".modal-footer").html("<button type='button' class='btn btn-info toLogin'>确认</button>"
				+"<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button>");
	});
	$(document).on("click",".toLogin",function(){
		window.location.href="../pages/login.html";	
	});
	
	//是否填写详情
	$("input[name='ifShowPersonal']").on("change",function(){
		var ifShow = $("input[name='ifShowPersonal']").get(0).checked;
		if(ifShow){
			//显示
			$(".showPersonalContent").show();
		}else{
			//隐藏
			$(".showPersonalContent").hide();
		}
	});
	$("input[name='ifShowEnterprise']").on("change",function(){
		var ifShow = $("input[name='ifShowEnterprise']").get(0).checked;
		if(ifShow){
			//显示
			$(".showEnterpriseContent").show();
		}else{
			//隐藏
			$(".showEnterpriseContent").hide();
		}
	});
	
	//个人注册
	$(".personalRegister").on("click",function(){
		$(".modal-footer").empty();
		$(".modal-footer").html("<button type='button' class='btn btn-info' data-dismiss='modal'>确认</button>");
		//参数获取
		var realName = $("#realName").val();
		var phoneNumber = $("#phoneNumber").val();
		var validateCode = $("#validateCode").val();
		var refereeName = $("#refereeName").val();
		var refereePhone = $("#refereePhone").val();
		//非空验证
		if(null != realName && realName != ""){
			if(null != phoneNumber && phoneNumber != ""){
				if(null != validateCode && validateCode != ""){
					if(null != refereeName && refereeName != ""){
						if(null != refereePhone && refereePhone != ""){
							$("#myModel").attr("aria-hidden","false");
							$("#myModalLabel").text("提示");
							$(".modal-body").text("注册完成,请扫描二维码后重新登录！");
							window.location.href="../pages/qrcode.html";
						}else{
							$("#myModel").attr("aria-hidden","false");
							$("#myModalLabel").text("错误提示");
							$(".modal-body").text("推荐人手机号不能为空!");
						}
					}else{
						$("#myModel").attr("aria-hidden","false");
						$("#myModalLabel").text("错误提示");
						$(".modal-body").text("推荐人姓名不能为空!");
					}
				}else{
					$("#myModel").attr("aria-hidden","false");
					$("#myModalLabel").text("错误提示");
					$(".modal-body").text("验证码不能为空!");
				}
			}else{
				$("#myModel").attr("aria-hidden","false");
				$("#myModalLabel").text("错误提示");
				$(".modal-body").text("手机号不能为空!");
			}
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("真实姓名不能为空!");
		}	
	});
	
	//企业注册
	$(".enterpriseRegister").on("click",function(){
		$(".modal-footer").empty();
		$(".modal-footer").html("<button type='button' class='btn btn-info' data-dismiss='modal'>确认</button>");
		//参数获取
		var enterpriseName = $("#enterpriseName").val();
		var enterpriseAddress = $("#enterpriseAddress").val();
		var connectWay = $("#connectWay").val();
		var enterpriseRefereeName = $("#enterpriseRefereeName").val();
		var enterpriseRefereePhone = $("#enterpriseRefereePhone").val();
		//非空验证
		if(null != enterpriseName && enterpriseName != ""){
			if(null != enterpriseAddress && enterpriseAddress != ""){
				if(null != connectWay && connectWay != ""){
					if(null != enterpriseRefereeName && enterpriseRefereeName != ""){
						if(null != enterpriseRefereePhone && enterpriseRefereePhone != ""){
							$("#myModel").attr("aria-hidden","false");
							$("#myModalLabel").text("提示");
							$(".modal-body").text("注册完成,请扫描二维码后重新登录！");
							window.location.href="../pages/qrcode.html";
						}else{
							$("#myModel").attr("aria-hidden","false");
							$("#myModalLabel").text("错误提示");
							$(".modal-body").text("推荐人手机号不能为空!");
						}
					}else{
						$("#myModel").attr("aria-hidden","false");
						$("#myModalLabel").text("错误提示");
						$(".modal-body").text("推荐人姓名不能为空!");
					}
				}else{
					$("#myModel").attr("aria-hidden","false");
					$("#myModalLabel").text("错误提示");
					$(".modal-body").text("联系方式不能为空!");
				}
			}else{
				$("#myModel").attr("aria-hidden","false");
				$("#myModalLabel").text("错误提示");
				$(".modal-body").text("企业地址不能为空!");
			}
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("企业名称不能为空!");
		}	
	});
	
	//注册详细
	$(".registerDetail").on("click",function(){
		$(".modal-footer").empty();
		$(".modal-footer").html("<button type='button' class='btn btn-info' data-dismiss='modal'>确认</button>");
		//参数获取
		var realName = $("#realName").val();
		var phoneNumber = $("#phoneNumber").val();
		var validateCode = $("#validateCode").val();
		var idCard = $("#idCard").val();
		var bankName = $("#bankName").val();
		var bankCard = $("#bankCard").val();
		var refereeName = $("#refereeName").val();
		var refereePhone = $("#refereePhone").val();
		//非空验证
		if(null != realName && realName != ""){
			if(null != phoneNumber && phoneNumber != ""){
				if(null != validateCode && validateCode != ""){
					if(null != idCard && idCard != ""){
						if(null != bankName && bankName != ""){
							if(null != bankCard && bankCard != ""){
								if(null != refereeName && refereeName != ""){
									if(null != refereePhone && refereePhone != ""){
										$("#myModel").attr("aria-hidden","false");
										$("#myModalLabel").text("提示");
										$(".modal-body").text("注册完成,请扫描二维码后重新登录！");
										window.location.href="../pages/qrcode.html";
									}else{
										$("#myModel").attr("aria-hidden","false");
										$("#myModalLabel").text("错误提示");
										$(".modal-body").text("推荐人手机号不能为空!");
									}
								}else{
									$("#myModel").attr("aria-hidden","false");
									$("#myModalLabel").text("错误提示");
									$(".modal-body").text("推荐人姓名不能为空!");
								}
							}else{
								$("#myModel").attr("aria-hidden","false");
								$("#myModalLabel").text("错误提示");
								$(".modal-body").text("银行卡号不能为空!");
							}
						}else{
							$("#myModel").attr("aria-hidden","false");
							$("#myModalLabel").text("错误提示");
							$(".modal-body").text("开户行不能为空!");
						}
					}else{
						$("#myModel").attr("aria-hidden","false");
						$("#myModalLabel").text("错误提示");
						$(".modal-body").text("身份证号不能为空!");
					}
				}else{
					$("#myModel").attr("aria-hidden","false");
					$("#myModalLabel").text("错误提示");
					$(".modal-body").text("验证码不能为空!");
				}
			}else{
				$("#myModel").attr("aria-hidden","false");
				$("#myModalLabel").text("错误提示");
				$(".modal-body").text("手机号不能为空!");
			}
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("真实姓名不能为空!");
		}	
	});
	
})